< previous page page_81 next page >

Page 81
Private Sub HScroll1_Change()
    Label1.Caption = "Search for " & Chr$(HScroll1.Value)
    'Insert code here to actually perform the db search
End Sub
Private Sub HScroll1_Scroll()
    Label1.Caption = "Release to select " & Chr$(HScroll1.Value)
End Sub
Run the program and watch the text in the label change as you manipulate the scrollbar. By putting code in the appropriate events, as in the example in Listing 4.1, you can have your program always display the exact value of the scrollbar but take action only when appropriate.
The Timer Control
As you may guess from looking at its icon, the Timer control works like a stopwatch or an alarm clock. However, three major differences exist between a timer in the real world and one in Visual Basic:
Instead of making a noise or beeping, the Timer control executes code (in its Timer event) when the interval is complete.
The Timer control counts down repeatedly, as long as the Enabled property is set to True.
The Timer control is designed to work with very small amounts of time; the maximum setting is just a little longer than a minute.
The Timer control has many uses, including scheduling and performing repeated operations.
Setting Up the Timer
You set up a Timer control by first drawing it on the form, as shown in Figure 4.18. The Timer control always shows up as an icon at designtime, but it does not show up at all while your program is running.
0081-01.jpg
Figure 4.18
The Timer control appears as an
icon, no matter what size you draw it.
To make the control work, you must first place code in the Timer event and then set the following properties, either at designtime or runtime:
1. Set the Interval property.
2. Set the Enabled property to True.
The Enabled property acts like a switch that turns your timer on and off. If the Timer control is enabled, the code in the Timer event is executed at the end of the time specified in the Inter-

 
< previous page page_81 next page >